package com.zkk.web;

import com.zkk.service.UserService;
import com.zkk.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static java.lang.Integer.parseInt;

@WebServlet("/delete")
public class deleteUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");  //注意在问号后面添加的？，传进来的值是字符串类型的
        UserService userService=new UserServiceImpl();
        userService.deleteById(parseInt(id));  //记住Integer.valueOf()的方法，还有parseInt方法，把字符串转为整型，还有个
        resp.sendRedirect("/findAll");  //这里删除后会立马让重新登入是因为拦截在生效

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
    }
}
